<html>
<meta charset="UTF-8">
<head>
    <title>人工智障-外挂</title>
    <!--<script src="https://unpkg.com/vue"></script>-->
    <script src="https://cdn.bootcss.com/vue/2.5.13/vue.min.js"></script>
	<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script type="text/javascript">
       
// 将粘贴事件绑定到 document 上
document.addEventListener("paste", function (e) {
    var cbd = e.clipboardData;
    var ua = window.navigator.userAgent;
    // 如果是 Safari 直接 return
    if ( !(e.clipboardData && e.clipboardData.items) ) {
        return;
    }
    // Mac平台下Chrome49版本以下 复制Finder中的文件的Bug Hack掉
    if(cbd.items && cbd.items.length === 2 && cbd.items[0].kind === "string" && cbd.items[1].kind === "file" &&
        cbd.types && cbd.types.length === 2 && cbd.types[0] === "text/plain" && cbd.types[1] === "Files" &&
        ua.match(/Macintosh/i) && Number(ua.match(/Chrome\/(\d{2})/i)[1]) < 49){
        return;
    }
    for(var i = 0; i < cbd.items.length; i++) {
        var item = cbd.items[i];
        if(item.kind == "file"){
            var blob = item.getAsFile();
            if (blob.size === 0) {
                return;
            }
             var reader = new FileReader();
    		reader.readAsDataURL(blob);
    		reader.onload = function(e){

    			var reg = /,/;
    			var base64str = e.target.result;
    			var resultArr = base64str.split(reg);
    			var finallyResultStr = resultArr[1];
    			if (window.app.niuBiMode){
                    axios.post('/cdapi/nb', {
                        imgbase: finallyResultStr
                    })
                        .then(function (response) {
                            console.log("牛逼模式请求成功",response.data.words_result);
                            var result = "";
                            var res = response.data.words_result.forEach(function (item,index,                           input) {
                                result = result+" "+item.words
                            })
                            window.app.message = result;
                            var regularStr = /\d*\./;
                            var regularStr2 = /\d*/;
                            var queryStr = result.replace(regularStr,"").replace(regularStr2,"");
                            var str = "https://www.baidu.com/s?ie=UTF-8&wd="+queryStr;
                            window.open (str, "newwindow"); //写成一行
                        })
                        .catch(function (error) {
                            console.log("失败",error);
                            window.app.message = "牛逼模式已精疲力尽,请切换智障模式";
//                    window.app.show = true;
                        });
                }else{
                    axios.post('/cdapi', {
                        imgbase: finallyResultStr
                    })
                        .then(function (response) {
                            console.log("成功",response.data.ret);
                            var result = "";
                            var res = response.data.ret.forEach(function (item,index,                           input) {
                                result = result+" "+item.word
                            })
                            window.app.message = result;
                            var regularStr = /\d*\./;
                            var regularStr2 = /\d*/;
                            var queryStr = result.replace(regularStr,"").replace(regularStr2,"");
                            var str = "https://www.baidu.com/s?ie=UTF-8&wd="+queryStr;
                            window.open (str, "newwindow"); //写成一行
                        })
                        .catch(function (error) {
                            console.log("失败",error);
                            window.app.message = "啊哦~看不出来";
//                    window.app.show = true;
                        });
                }

    		};
//            console.log(blob)

        }
    }
}, false);

</script>
    <style>
        #app{
            text-align:center;
        }
        h3{
            /*width: 100%;*/
            /*background-color: rebeccapurple;*/
            color: red;
        }
        #copyright{
            /*text-align:center;*/
            position: absolute;
            bottom:20px;
            left: 45%;
        }
        #niuBiModeDIV{
            border: dashed 1px;
        }
    </style>
</head>
<body>
<div id="app">
    <div id="niuBiModeDIV" @click="niuBiMode=!niuBiMode">{{niuBiModeMsg}}</div>
    <h4>智能识别图中文字,自动去题号,并调用百度搜索,让你更快抢答</h4>
    <p>'人工智障'使用教程</p>
    <p v-for="item in arr">{{item}}</p>
    <p>注意:请使用chrome浏览器,查询完成如果没有自动百度,请在浏览器地址栏最后找,有个按钮,点击选择'始终允许弹出式窗口'.  截图请让文字周围留有空白</p>
    <h3>识别结果是</h3>
    <h3>{{ message }}</h3>
    <img src="http://img4.imgtn.bdimg.com/it/u=2707988359,3096912910&fm=214&gp=0.jpg" v-show="message=='啊哦~看不出来'">
    <p id="copyright">@copyright: summer</p>
</div>
<script>
    var app = new Vue({
        el: '#app',
        data: {
            message: '',
            arr:["0.使用itools连接iphone,点击工具箱->实时桌面->!!全屏!!(安卓同理,总之只要把手机桌面投影到电脑上就行)","1.使用QQ截图从上一步的实时桌面中截取需要识别的图(为了保证正常,不要有干扰项)","2.截图完成后鼠标单击本页面!!!!!!保证当前窗口在最前!!!!!","3.ctrl+v粘贴","4.等待结果"],
            niuBiMode:false,
            niuBiModeMsg:"当前为人工智障模式(识别可能有误差),点击切换"
        },
        watch: {
            niuBiMode(newval){
                if (newval){
                    this.niuBiModeMsg = "当前为牛逼🐂模式(使用次数极其有限),点击切换为普通模式"
                }else{
                    this.niuBiModeMsg = "当前为人工智障模式(使用次数无限),点击切换"
                }
            }
        }
    })
</script>
</body>
</html>